<?php

namespace IMT\EventBundle\Models;

use Symfony\Component\Config\Definition\Exception\InvalidTypeException;

use Doctrine\ORM\EntityManager;

use IMT\EventBundle\Entity\Event;

use Symfony\Component\Security\Acl\Model\AclProviderInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;

class EventManagerFactory
{
	private $entityManager;
	private $classes;
	
	public function __construct(EntityManager $entityManager)
	{
		$this->classes = array();
		$this->entityManager = $entityManager;
	}
	
	public function getManager(EventInterface $event)
	{
		foreach($this->classes as $classEvent => $classManager){
			if($event instanceof $classEvent)
				return new $classManager($this->entityManager, $classEvent);
		}
		
		throw new InvalidTypeException('Le type de l\'event est invalide ou n\'a pas été ajouté à l\'EntityManagerFactory');
	}
}